package com.alibaba.druid.sql.dialect.mysql.ast.expr;

import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLExprImpl;
import com.alibaba.druid.sql.ast.SQLObject;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;


















public class MySqlIntervalExpr
        extends SQLExprImpl
        implements MySqlExpr
{
    private SQLExpr value;
    private MySqlIntervalUnit unit;

    public SQLExpr getValue() { return this.value; }



    public void setValue(SQLExpr value) { this.value = value; }



    public MySqlIntervalUnit getUnit() { return this.unit; }



    public void setUnit(MySqlIntervalUnit unit) { this.unit = unit; }



    public void output(StringBuffer buf) {
        this.value.output(buf);
        buf.append(' ');
        buf.append(this.unit.name());
    }


    protected void accept0(SQLASTVisitor visitor) { acceptChild(visitor, (SQLObject)this.value); }



    public int hashCode() {
        int prime = 31;
        int result = 1;
        result = 31 * result + ((this.unit == null) ? 0 : this.unit.hashCode());
        result = 31 * result + ((this.value == null) ? 0 : this.value.hashCode());
        return result;
    }


    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        MySqlIntervalExpr other = (MySqlIntervalExpr)obj;
        if (this.unit != other.unit) {
            return false;
        }
        if (this.value == null) {
            if (other.value != null) {
                return false;
            }
        } else if (!this.value.equals(other.value)) {
            return false;
        }
        return true;
    }
}
